import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
import axios from 'axios';

const { createConfirm } = useMessage();

enum Api {
  list = '/school/schoolProject/list',
  save = '/school/schoolProject/add',
  edit = '/student_student/schoolProject/edit',
  deleteOne = '/student_student/schoolProject/delete',
  deleteBatch = '/student_student/schoolProject/deleteBatch',
  importExcel = '/student_student/schoolProject/importExcel',
  exportXls = '/student_student/schoolProject/exportXls',
  projectlist = '/school/schoolProject/list',
  queryByPath = '/school/schoolProject/queryByPath',
  addPath = '/school/schoolProject/addPath',
  deletePath = '/school/schoolProject/deleteRoute',
  rename = '/school/schoolProject/rename',
  fileReader = '/school/schoolProject/fileReader',
  fileWrite = '/school/schoolProject/fileWrite',
  uploadFileProject = '/school/schoolProject/uploadFileProject',
}
// export const queryByPath = (projectPath?: any) => defHttp.get({ url: `${Api.queryByPath}?projectPath=${projectPath}` });
export const queryByPath = (projectPath?: any) => {
  const url = projectPath ? `${Api.queryByPath}?projectPath=${projectPath}` : Api.queryByPath;
  return defHttp.get({ url });
};
export const rename = (saveAddress: any, oldObjectName: any, newObjectName: any) => {
  const url = `${Api.rename}?saveAddress=${saveAddress}&oldObjectName=${oldObjectName}&newObjectName=${newObjectName}`;
  return defHttp.get({ url });
};
export const test = () => axios.get('https://static.zhihu.com/heifetz/chunks/3175.b30049c8380dfc063a4d.js');
/**}
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
export const fileWrite = (params) => defHttp.post({ url: Api.fileWrite, params });
export const addPath = (params) => defHttp.post({ url: Api.addPath, params });
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });
export const projectlist = () => defHttp.get({ url: Api.projectlist });
export const fileReader = (filePath: any) => defHttp.get({ url: `${Api.fileReader}?filePath=${filePath}` });
/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除
 * @param params
 */

export const deletePath = (routeDelete: string) => {
  return defHttp.delete({ url: `${Api.deletePath}?routeDelete=${routeDelete}` });
};

export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};
export const uploadFileProject = (params) => {
  return defHttp.uploadFile({ url: Api.uploadFileProject }, params);
};
